

/***************************** Include Files *******************************/
#include "axis_dma_sender.h"
#include "xil_io.h"
/************************** Function Definitions ***************************/
void DMA_SENDER_init(DmaTrans* p, uint32_t base_addr){
    uint32_t k = AXIS_DMA_SENDER_mReadReg(base_addr, 0);
    p->base_addr = base_addr;
    p->enable = (k & (1 << 31)) == (1 << 31) ? 1 : 0;
    p->start_pos = (k & 0x7fff0000) >> 16;
    p->trans_num = (k & 0x0000ffff);
}

void DMA_SENDER_setStart(DmaTrans* p){
    p->enable = 1;
    uint32_t data = (p->enable << 31) | (p->start_pos & 0x00007fff) << 16 | p->trans_num;
    AXIS_DMA_SENDER_mWriteReg(p->base_addr, 0, data);
}

void DMA_SENDER_setStop(DmaTrans* p){
    p->enable = 0;
    uint32_t data = (p->enable << 31) | (p->start_pos & 0x00007fff) << 16 | p->trans_num;
    AXIS_DMA_SENDER_mWriteReg(p->base_addr, 0, data);
}

void DMA_SENDER_setTransSize(DmaTrans* p, uint16_t trans_size){
    p->trans_num = trans_size;
    uint32_t data = (p->enable << 31) | (p->start_pos & 0x00007fff) << 16 | p->trans_num;
    AXIS_DMA_SENDER_mWriteReg(p->base_addr, 0, data);
}

void DMA_SENDER_setTransStartPos(DmaTrans* p, uint16_t start_pos){
    p->start_pos = start_pos;
    uint32_t data = (p->enable << 31) | (p->start_pos & 0x00007fff) << 16 | p->trans_num;
    AXIS_DMA_SENDER_mWriteReg(p->base_addr, 0, data);
}